import request from '@/utils/request';
import type { ListBaseQuery, ListData, ResBody } from './common';
import { UserVO } from '../system/user/types';

export enum CarStandards {
  small = 0,
  big = 1
}

export enum CarStatus {
  normal = 0,
  loading = 1,
  transiting = 2
}

export interface CarData {
  id: number;
  driverId: string | number;
  carNumber: string;
  driverName: string;
  driverPhone: string;
  standards: CarStandards;
  status: CarStatus;
  remark: string;
}

export interface CarListQuery extends ListBaseQuery {
  driverId?: number;
  carNumber?: string;
  driverName?: string;
  standards?: CarStandards;
  remark?: string;
}

export const getDriverList = (query: ListBaseQuery): Promise<ListData<UserVO>> =>
  request.post('/system/role/authUser/driverList', { ...query, roleld: '1816430524247711745' });

export const getCarList = (params: CarListQuery): Promise<ListData<CarData>> => request.get('/wuliu/car/list', { params });

export const createCar = (data: Partial<CarData>): ResBody => request.post('/wuliu/car', data);

export const updateCar = (data: Partial<CarData>): ResBody => request.put('/wuliu/car', data);

export const delCar = (ids: number | number[]): ResBody => {
  if (!Array.isArray(ids)) {
    ids = [ids];
  }

  return request.delete(`/wuliu/car/${ids.join(',')}`);
};
